package com.xdwanj.criminalintent.viewmodel;

import android.util.Log;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.ViewModel;

import com.xdwanj.criminalintent.pojo.Crime;
import com.xdwanj.criminalintent.repository.CrimeRepository;

import java.util.ArrayList;
import java.util.List;

public class CrimeListViewModel extends ViewModel {
    private final static String TAG = "CrimeListViewModel";

    private final CrimeRepository crimeRepository = CrimeRepository.get();

    public LiveData<List<Crime>> crimeListLiveData = crimeRepository.ListCrime();

    //构造访法 初始化数据
    public CrimeListViewModel() {
        super();
    }

    public void addCrime(Crime crime) {
        crimeRepository.addCrime(crime);
    }

    /**
     * 当ViewModel销毁时调用
     */
    @Override
    protected void onCleared() {
        super.onCleared();
        Log.d(TAG, "onCleared: CrimeListViewModel is destroy");
    }
}
